<?php

use console\services\MigrateService;
use yii\db\Migration;

/**
 * Handles the creation of table `sys_dept`.
 */
class m231229_144106_create_sys_dept_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('sys_dept', [
            'id' => $this->bigPrimaryKey(),
            'name' => $this->string(64)->defaultValue('')->notNull()->comment('名称'),
            'parent_id' => $this->bigInteger()->defaultValue(0)->notNull()->comment('父部门id'),
            'parent_name' => $this->string(255)->defaultValue('')->null()->comment('父级名称'),
            'levels' => $this->string(128)->defaultValue('')->null()->comment('父级列表'),
            'leader' => $this->string(32)->defaultValue('')->null()->comment('负责人'),
            'phone' => $this->string(32)->defaultValue('')->null()->comment('联系电话'),
            'email' => $this->string(64)->defaultValue('')->null()->comment('联系电话'),
            'status' => $this->char(1)->defaultValue('1')->null()->comment('状态'),
            'list_sort' => $this->bigInteger()->defaultValue(10)->null()->comment('排序'),
            'remark' => $this->string(255)->defaultValue('')->null()->comment('备注'),
            'create_time' => $this->bigInteger()->defaultValue(0)->null()->comment('创建时间'),
            'update_time' => $this->bigInteger()->defaultValue(0)->null()->comment('更新时间'),
        ], MigrateService::createTableOptions('部门表'));

        $this->batchInsert('sys_dept',
            ['id', 'name', 'parent_id', 'parent_name', 'levels', 'status', 'list_sort'],
            [
                [100, '冰舞科技', 0, '', '0', '1', 0],
                [101, '北京总公司', 100, '冰舞科技', '0,100', '1', 4],
                [102, '研发部门', 101, '冰舞科技,北京总公司', '0,100,101', '1', 1],
                [103, '市场部门', 101, '冰舞科技,北京总公司', '0,100,101', '1', 2],
                [104, '山东分公司', 100, '冰舞科技', '0,100', '1', 2],
                [111, '销售部门', 104, '冰舞科技,山东分公司', '0,100,110', '1', 1],
            ]
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $this->dropTable('sys_dept');
    }
}
